home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group94a.txt / 000177_icon-group-sender _Thu Jun 16 12:27:04 1994.msg < prev    next >
Internet Message Format  |  1994-08-19  |  2KB

  1. Received: by cheltenham.cs.arizona.edu; Thu, 16 Jun 1994 15:11:29 MST
  2. Date: Thu, 16 Jun 94 12:27:04 PDT
  3. From: eric@star-semi.com (Eric Armstrong)
  4. Message-Id: <9406161927.AA07961@star-semi.com>
  5. To: icon-group@cs.arizona.edu
  6. Subject: booleans, enumerations, globals
  7. Status: R
  8. Errors-To: icon-group-errors@cs.arizona.edu
  9.  
  10. I am just beginning to come to grips with the wonderful expressive power
  11. of Icon's expression evaluation, so I'm learning to combine expressions in
  12. ways that implement algorithmns succinctly.  But some parts of my code are
  13. beginning to look pretty ugly.  I'm wondering what idioms you guys use to:
  14.  
  15.     a. Do a simple boolean test, like
  16.         if a=true    -or-   if a=false
  17.  
  18.        At the moment, I'm doing a horrible global definition of true
  19.        and false, and initializing them at the beginning of the main
  20.        routine.  Incredibly ugly.  Immediately begins to obscure an
  21.        otherwise comprehensible algorithm.
  22.  
  23.     b. Create something like a Pascal enumeration type
  24.        Days of the week, for example.  I create a list of strings:
  25.        ["Mon", "Tue", ...] but then I index it by a number (weekday[2]).
  26.        How would it be possible to index it as weekday[Tue]?
  27.  
  28.     c. initialize globals
  29.        The "initial" clause is really excellent in procedures.  Its primary
  30.        value is that it lets me put initial values in the same place that
  31.        the variables are used, instead of miles away in some initialization
  32.        routine.  But every time I need a global, I wind up doing that 
  33.        same old initialization schtick.  (More than I would like to, as
  34.        a result of issues #1 and #2.)
  35.  
  36. Hopefully, there are some idomatic themes that will alleviate these problems.
  37. I look forward to your replies.
  38.